package cn.ococci.dm.Main.Tools;

import android.content.Context;
import android.view.View;
import android.widget.AbsListView;

import cn.ococci.dm.Main.View.Dialog.CustomDialog;
import cn.ococci.dm.Main.View.Dialog.DialogAdapter;


/**
 * Created by cyan on 15/9/21.
 * 通用对话框工具类
 */
public class DialogTool {
    /**
     * 创建一个自定义的对话框
     * @param context
     * @param adapter
     * @return
     */
    public static CustomDialog createMaterialDialog(Context context, DialogAdapter adapter){
        CustomDialog dialog = new CustomDialog(context);
        dialog.setDialogAdapter(adapter);
        dialog.show();
        return dialog;
    }


    /**
     * 显示列表Dialog
     * @param context
     * @param title
     * @param list
     * @param cancelAction
     * @return
     */
    public static CustomDialog showListDialog(Context context, final String title, final AbsListView list, final Runnable cancelAction) {

        DialogAdapter adapter = new DialogAdapter() {

            @Override
            public CharSequence caption() {
                return title;
            }

            @Override
            public boolean confirm() {

                if (cancelAction != null) {

                    cancelAction.run();
                }
                return super.confirm();
            }


            @Override
            public CharSequence[] btnNames() {

                return new CharSequence[]{"取消"};
            }


            @Override
            public View getListViewContentView() {
                return list;
            }
        };


        return createMaterialDialog(context,adapter);

    }



}
